package com.sumainfor.pc.dev.controller.tenant;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.dev.service.TenantIndexService;
import com.sumainfor.pc.dev.service.impl.MovableService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Jack Chen
 * @Create 2019-02-22 14:31
 * 首页
 */
@RestController
@RequestMapping("/tenant/key/index")
public class TenantIndexController {

    @Autowired
    private TenantIndexService indexService;

    @Autowired
    MovableService MovableService;

    /**
     * 获得首页Banner 列表数据
     *
     * @return
     */
    @PostMapping("/getIndexBanner")
    public JsonResult getIndexBanner() {
        List<Map<String, Object>> dataList = indexService.getIndexBanner();
        return JsonResult.success(dataList);
    }

    /**
     * 获得首页热门房源信息
     *
     * @return
     */
    @PostMapping("/getHotHousingIndexData")
    public JsonResult getHotHousingIndexData() {
        return JsonResult.success(indexService.getHotHousingIndexData());
    }

    /**
     * 获得所有的热门房源信息数据
     *
     * @return
     */
    @PostMapping("/getHotHousingAll")
    public JsonResult getHotHousingAll() {
        return JsonResult.success(indexService.getHotHousingAll());
    }

    /**
     * 获得租房攻略
     *
     * @param page
     * @return
     */
    @RequestMapping("/getRaidersMainList")
    public JsonResult getRaidersMainList(Page page) {
        return JsonResult.success(indexService.getRaidersMainList(page));
    }

    /**
     * 根据租房攻略主编号查询所有的内部房源
     *
     * @param page
     * @param raId
     * @return
     */
    @RequestMapping("/getRaidersInfoDataByRaId")
    public JsonResult getRaidersInfoDataByRaId(Page page, String raId) {
        if (StringUtils.isBlank(raId)) {
            return JsonResult.errorForEmpty();
        }
        return JsonResult.success(indexService.getRaidersInfoDataByRaId(page, raId));
    }

    /**
     * 功能描述: 
     * 获取首页活动
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/10 14:15
     */
    @ResponseBody
    @RequestMapping(value = "/getMovableList",method = RequestMethod.GET)
    public JsonResult getMovableList(){
        JsonResult result=new JsonResult();
        Map<String,Object>params=new HashMap<String,Object>();
        Pager pager=new Pager();
        params.put("delfg",0);
        params.put("pageno",0);
        params.put("pagesize",2);
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=MovableService.getMovableListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getMovableList=MovableService.getMovableList(params);
        result=pageUtils.getJsonResult(getMovableList, params, cout);
        return result;
    }

    /**
     * 功能描述: 
     * 根据编号获取首页活动详情
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/10 15:22
     */
    @GetMapping("/getMovableMap")
    public JsonResult getMovableMap(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        params.put("delfg",0);
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"MovId"})){
            result.putFailed("MovId不能为空！");
            return  result;
        }
        Map<String,Object>getMovableMap=MovableService.getMovableMap(params);
        return result.put(getMovableMap);
    }

    /**
     * 功能描述: 
     * 根据活动编号获取活动和房源中间表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/12 18:05
     */
    @GetMapping("/getMovableHousingList")
    public JsonResult getMovableHousingList(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"MovId"})){
            result.putFailed("MovId不能为空！");
            return  result;
        }
        result.put(MovableService.getMovableHousingList(params));
        return result;
    }
}
